#ifndef __UDPCS_H
#define __UDPCS_H

#include<functional>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<netinet/in.h>

#include<thread>
#include<chrono>

#include<pthread.h>

#include"timer.h"

using namespace std;

#define BUFF_LINE 512
#define BUFF_LINE_2 1024





/***************************************
			Class UdpCs
***************************************/
class UdpCs
{
public:
	UdpCs();
	~UdpCs();


	/*
	client
		UdpCs udp_cs;
		udp_cs.run_sender();
	*/
	void run_sender();
	void preset_sender();
	void start_sender();
	void end_sender();

	void stop_sender();

	/*
	server
		UdpCs udp_cs;
		udp_cs.run_receiver();
	*/
	void run_receiver();
	void preset_receiver();
	void start_receiver();

	void stop_receiver();

//private:
	bool sender_running ;
	bool receiver_running ;



	int client_fd;
	int server_fd;
	struct sockaddr_in ser_addr;

	int server_port;
	int buf_send_line;
	string server_ip = "10.0.16.2";	

};

/***************************************
			Class UdpController
***************************************/
class UdpController
{
public:
	UdpController(){};
	~UdpController(){};
	static void udpCs_install( UdpCs *udpCs );
	static void udpCs_stop_sender();
	static void udpCs_stop_receiver();
	
//private:
	static UdpCs *udpCs_ptr;
};

//UdpCs *UdpController::udpCs_ptr = NULL;

/***************************************
			Class UdpThread
***************************************/
class UdpThread
{
public:
	/*
	thread
		run independent sender&receiver
	*/
	UdpThread();
	~UdpThread();
	void run_independent_sender();
	void run_independent_receiver();
	void wait_for_sender();
	void wait_for_receiver();

//private:
	UdpCs udpCs;
	thread *t_receiver;
	thread *t_sender;
};


#endif
